using Orchard;
using Orchard.ContentManagement.MetaData;
using Orchard.Core.Contents.Extensions;
using Orchard.Data.Migration;

namespace Szmyd.Orchard.Modules.Silverlight {
    public class SilverlightDataMigration : DataMigrationImpl {
        private readonly IOrchardServices _services;

        public SilverlightDataMigration(IOrchardServices services) {
            _services = services;
        }

        public int Create() {
            
            SchemaBuilder.CreateTable("SilverlightPartRecord",
               table => table
                   .ContentPartRecord()
                   .Column<string>("Source")
                   .Column<string>("MinRuntimeVersion")
                   .Column<string>("InitParams")
                   .Column<bool>("AutoUpdate", c => c.Nullable())
                   .Column<int>("Width", c => c.Nullable())
                   .Column<int>("Height", c => c.Nullable())
               );

            
            ContentDefinitionManager.AlterTypeDefinition("SilverlightWidget",
               cfg => cfg
                   .WithPart("SilverlightPart")
                   .WithPart("CommonPart")
                   .WithPart("WidgetPart")
                   .WithSetting("Stereotype", "Widget")
               );

           
            ContentDefinitionManager.AlterTypeDefinition("SilverlightPage", 
                cfg=>cfg
                .WithPart("CommonPart")
                .WithPart("PublishLaterPart")
                .WithPart("RoutePart")
                .WithPart("SilverlightPart")
                .WithPart("MenuPart")
                .Creatable()
                .DisplayedAs("Silverlight Page"));

            ContentDefinitionManager.AlterPartDefinition("SilverlightPart", cfg => cfg.Attachable());

            return 1;
        }
    }
}